package org.thingsboard.server.utils;

import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class AjaxResult extends HashMap<String, Object> implements Serializable {

    private Map responseHead;

    private Object responseBody;


    /**
     * 返回成功消息
     *
     * @param data 数据对象
     * @return 成功消息
     */
    public   AjaxResult(int code,String message,Object data)
    {
        Map map=new HashMap();
        map.put("code",code);
        map.put("timestamp",System.currentTimeMillis());
        map.put("message",message);
        super.put("responseHead",map);
        super.put("responseBody",data);
    }
    public static AjaxResult success()
    {
        return new AjaxResult(0,null,null);
    }
    public static AjaxResult success(String message)
    {
        return new AjaxResult(0,message,null);
    }
    public static AjaxResult success(Object data)
    {
        return new AjaxResult(0,null,data);
    }

    public static AjaxResult error(String message)
    {
        return new AjaxResult(400,message,null);
    }
    public static AjaxResult error(ThingsboardErrorCode errorCode)
    {
        return new AjaxResult(errorCode.getErrorCode(),errorCode.getMessage(),null);
    }

}
